﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HomeBudget
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MoneySystem moneySystem = new MoneySystem();
        public InvalidMoney invalidMoneyCast = new InvalidMoney("Please enter a amount!");
        public InvalidMoney invalidMoneyNegativeNumber = new InvalidMoney("The amount must be a positive number!");
        public InvalidItemName invalidItemName = new InvalidItemName("Please, enter a name!");

        public MainWindow()
        {
            InitializeComponent();
            var loadedExpenses = Database.LoadFromExpenseFile();
            var loadedIncomes = Database.LoadFromIncomeFile();
            foreach (var item in loadedExpenses)
            {
                moneySystem.AddExpense(item as Expense);
            }
            foreach (var item in loadedIncomes)
            {
                moneySystem.AddEarning(item as Earning);
            }
            Renderer.WriteInformation(this.listBoxGridIncome, moneySystem.GetEarningsAsMoney());
            Renderer.WriteInformation(this.listBoxGridEpense, moneySystem.GetExpensesAsMoney());
            ShowMoneyNow();
        }
        public void ShowMoneyNow()
        {
            decimal moneyNow = moneySystem.CalculateMoneyNow();
            if (moneyNow < 0)
            {
                this.Balance.Foreground = Brushes.Red;
            }
            else
            {
                this.Balance.Foreground = Brushes.YellowGreen;
            }
            this.Balance.Text = moneyNow.ToString();
        }
        private void onAddOneTimeExpenseClick(object sender, RoutedEventArgs e)
        {
            OneTimeExpenseWindow expenseOneTimeWindow = new OneTimeExpenseWindow();
            expenseOneTimeWindow.Show();
        }

        private void onAddOneTimeIncomeClick(object sender, RoutedEventArgs e)
        {
            OneTimeIncomeWindow incomeOneTimeWindow = new OneTimeIncomeWindow();
            incomeOneTimeWindow.Show();
        }

        private void onAddRecurringIncomeClick(object sender, RoutedEventArgs e)
        {
            RecurringIncomeWindow incomeRecurringTimeWindow = new RecurringIncomeWindow();
            incomeRecurringTimeWindow.Show();
        }

        private void onAddRecurringExpenseClick(object sender, RoutedEventArgs e)
        {
            RecurringExpenseWindow expenseRecurringTimeWindow = new RecurringExpenseWindow();
            expenseRecurringTimeWindow.Show();
        }
    }
}
